package com.dylan.equipment.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.dylan.equipment.dao.IUserDao;
import com.dylan.equipment.entity.PageBean;
import com.dylan.equipment.entity.User;
import com.dylan.equipment.utils.StringUtil;


@Service
public class UserService {
	@Resource
	private IUserDao userDao;
	
	public int userCount(User user){
		return userDao.count(user);
	}
	public User loginUser(User u){
		return userDao.login(u);
	}
	
	public List<User> loadUserList(PageBean page,User user){
		Map<String, Object> params = new HashMap<>();
		params.put("start", page.getStart());
		params.put("pageSize", page.getPageSize());
		if(user!=null){
			if(!StringUtil.isEmpty(user.getUserName())){
				params.put("userName", user.getUserName());
			}
		}
		List<User> userList = userDao.findByParams(params);
		return userList;
	}
	
	public void delete(int id){
		userDao.delete(id);
	}
    
	public User loadById(int id){
		return userDao.loadById(id);
	}
	
	public void add(User user){
		userDao.add(user);
	}
	public void update(User user){
		userDao.update(user);
	}
	public boolean existUserByDeptId(int deptId){
		List<User> users = userDao.existUserByDeptId(deptId);
		if(users.isEmpty()){
			return false;
		}else{
			return true;
		}
	}
}
